home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / FORM_DO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  12.4 KB  |  510 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "XA_DEFS.H"
  15. #include "BOX3D.H"
  16. #include "FRM_ALRT.H"
  17. #include "K_DEFS.H"
  18. #include "RESOURCE.H"
  19. #include "OBJECTS.H"
  20. #include "WATCHBOX.H"
  21. #include "C_WINDOW.H"
  22. #include "STD_WIDG.H"
  23.  
  24. #if 0
  25. #define CLIP(tree,obj,x,y,w,h)                 \
  26.     object_abs_coords(tree, obj, &x, &y);    \
  27.     w = tree[obj].ob_width;                    \
  28.     h = tree[obj].ob_height;                \
  29.     set_clip(x, y, w, h);
  30. #endif
  31.  
  32. #define CLIP(tree,obj,x,y,w,h)    clear_clip()
  33. #define set_clip(x,y,w,h)        /* We don't want this now! */
  34.  
  35. #if 0
  36. #undef CLIP            /* Those set_clip(..) can't be useful */
  37. #endif
  38.  
  39. /* Returns the object number of this object's parent or -1 if it is the root*/
  40. short GetParent(OBJECT *t, short object)
  41. {
  42.     short last;
  43.     
  44.     if (object == 0)
  45.         return -1;
  46.     else {
  47.         do {
  48.             last = object;
  49.             object = t[object].ob_next;
  50.         } while(t[object].ob_tail != last);
  51.         return object;
  52.     }
  53. }
  54.  
  55. /*
  56.   Sets one of a group of radio buttons, and clears the rest.
  57.   Includes patch to allow for pop_icons as radio buttons.
  58. */
  59. void Radio_b(OBJECT *d, short object)
  60. {
  61.     short parent, o, x, y, w, h;
  62.  
  63.     if ((parent = GetParent(d, object)) == -1)
  64.         return;        /* Only reasonable thing to do */
  65.  
  66.     o = d[parent].ob_head;
  67.     
  68.     while (o != parent)
  69.     {
  70.         if ((d[o].ob_flags & RBUTTON) && (d[o].ob_state & SELECTED))
  71.         {
  72.             d[o].ob_state &= ~SELECTED;
  73.  
  74.             CLIP(d, o, x, y, w, h);
  75.             v_hide_c(V_handle);
  76.             draw_object_tree(d, o, MAX_DEPTH);
  77.             v_show_c(V_handle, 1);
  78.         }
  79.         
  80.         o = d[o].ob_next;
  81.     }
  82.     
  83.     d[object].ob_state |= SELECTED;
  84.  
  85.     CLIP(d, object, x, y, w, h);
  86.     v_hide_c(V_handle);
  87.     draw_object_tree(d, object, MAX_DEPTH);
  88.     v_show_c(V_handle, 1);
  89. }
  90.  
  91. /*
  92.     Form_do() click handler
  93. */
  94. short click_object_widget(XA_WINDOW *wind, XA_WIDGET *widg)
  95. {
  96.     short x, y, w, h, f, is, os;
  97.     unsigned long retv = XA_OK;
  98.     XA_WIDGET_TREE *wt = (XA_WIDGET_TREE*)widg->stuff;
  99.     OBJECT *form;
  100.  
  101. #if 0
  102.     if (window_list != wind)    /* You can only work alerts when they are on top */
  103.         return FALSE;
  104. #endif
  105.     if (window_list != wind) {
  106.         v_hide_c(V_handle);
  107.         pull_wind_to_top(wind);
  108.         display_window(wind);
  109.         v_show_c(V_handle, 1);
  110.         return FALSE;
  111.     }
  112.    
  113.     form = wt->tree;
  114.  
  115.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  116.  
  117.     f = find_object(form, 0, 10, x + widg->click_x, y + widg->click_y);
  118.  
  119.     /* find_object can't report click on a HIDETREE object. */
  120. #if 0
  121.     if (((form[f].ob_flags & HIDETREE)        /* Was click on a valid selectable object? */
  122. #endif
  123.     if ((form[f].ob_state & DISABLED)    /* Was click on a valid selectable object? */
  124.         ||(!(form[f].ob_flags & (EDITABLE | SELECTABLE | EXIT | TOUCHEXIT))))
  125.     {    
  126.         return FALSE;
  127.     }
  128.  
  129.     if ((form[f].ob_flags & EDITABLE) && (f != wt->edit_obj))    /* Select a new editable text field? */
  130.     {
  131.         TEDINFO *txt=(TEDINFO*)form[f].ob_spec;
  132.         
  133.         form[f].ob_state |= IS_EDIT;
  134.         form[wt->edit_obj].ob_state &= ~IS_EDIT;
  135.  
  136.         CLIP(form, wt->edit_obj, x, y, w, h);
  137.         v_hide_c(V_handle);
  138.         draw_object_tree(form, wt->edit_obj, MAX_DEPTH);
  139.  
  140.         wt->edit_obj = f;
  141.         wt->edit_pos = txt->te_tmplen = strlen(txt->te_ptext);
  142.         
  143.         CLIP(form, f, x, y, w, h);
  144.         draw_object_tree(form, f, MAX_DEPTH);
  145.         v_show_c(V_handle, 1);
  146.     }
  147.  
  148.     CLIP(form, f, x, y, w, h);
  149.  
  150.     os = form[f].ob_state;
  151.     is = os ^ SELECTED;
  152.  
  153.      if (form[f].ob_flags & TOUCHEXIT)    /* Touch Exit button? */
  154.     {
  155.         if (form[f].ob_flags & RBUTTON) {    /* Was click on a radio button? */
  156.             Radio_b(form, f);
  157.         } else if (form[f].ob_flags & SELECTABLE) {
  158.             form[f].ob_state = is;
  159.             v_hide_c(V_handle);
  160.             draw_object_tree(form, f, MAX_DEPTH);
  161.             v_show_c(V_handle, 1);
  162.         }
  163.  
  164.  
  165.         clients[wt->owner].waiting_pb->intout[0] = f;
  166.         Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  167.         if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  168.         {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  169.             clients[wt->owner].zen = NULL;
  170.             v_hide_c(V_handle);
  171.             display_windows_below(wind);
  172.             v_show_c(V_handle, 1);
  173.             wind->is_open = FALSE;
  174.             delete_window(wind);
  175.         }
  176. /*
  177.  * How should an EXIT but not SELECTABLE be handled?
  178.  */
  179.     } else if (form[f].ob_flags & SELECTABLE) {    /* Selectable object? */
  180.  
  181. /*
  182.  * Should this perhaps be done in watch_object?
  183.  */
  184.         form[f].ob_state = is;
  185.         CLIP(form, f, x, y, w, h);
  186.         v_hide_c(V_handle);
  187.         draw_object_tree(form, f, MAX_DEPTH);
  188.         v_show_c(V_handle, 1);
  189.  
  190.         if (watch_object(form, f, is, os))
  191.         {
  192. #ifdef CLIP
  193.             set_clip(x, y, w, h);
  194. #endif
  195.     
  196.             if (form[f].ob_flags & RBUTTON)    /* Was click on a radio button? */
  197.             {
  198.                 Radio_b(form, f);
  199.             }
  200.                     
  201.             if (form[f].ob_flags & EXIT)        /* Exit button? */
  202.             {
  203.                 clients[wt->owner].waiting_pb->intout[0] = f;
  204.                 Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  205.     
  206.                 if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  207.                 {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  208.                     clients[wt->owner].zen = NULL;
  209.                     v_hide_c(V_handle);
  210.                     display_windows_below(wind);
  211.                     v_show_c(V_handle, 1);
  212.                     wind->is_open = FALSE;
  213.                     delete_window(wind);
  214.                 }
  215.             }
  216.             
  217.         }
  218.     }
  219.     
  220. #ifdef CLIP
  221.     clear_clip();
  222. #endif
  223.     
  224.     return FALSE;
  225. }
  226.  
  227. /*
  228.     Form Keyboard Handler
  229. */
  230. short handle_form_key(XA_WINDOW *wind, unsigned short keycode)
  231. {
  232.     XA_WIDGET *widg = (wind->widgets) + XAW_TOOLBAR;
  233.     XA_WIDGET_TREE *wt;
  234.     OBJECT *form;
  235.     TEDINFO *ed_txt;
  236.     unsigned long retv = XA_OK;
  237.     char *txt;
  238.     short cursor_pos, o, ed_obj, x, y, w, h, last_ob;
  239.     int key, tmask, n, update = 0;
  240.     
  241.     DIAGS(("handle_form_key()\n"));
  242.     
  243.     wt = (XA_WIDGET_TREE*)widg->stuff;
  244.     form = wt->tree;
  245.     ed_obj = wt->edit_obj;
  246.     ed_txt = (TEDINFO*)form[ed_obj].ob_spec;
  247.     txt = ed_txt->te_ptext;
  248.     cursor_pos = ed_txt->te_tmplen;
  249.  
  250.     DIAGS(("got keypress in form\n"));
  251.     
  252.     switch(keycode)
  253.     {
  254.     case 0x011b:        /* ESCAPE clears the field */
  255.         txt[0] = '\0';
  256.         ed_txt->te_tmplen = wt->edit_pos = 0;
  257.         update = 1;
  258.         break;
  259.  
  260.     case 0x537f:        /* DEL deletes character after cursor */
  261.         if (txt[cursor_pos])
  262.         {
  263.             for(x = cursor_pos; x < ed_txt->te_txtlen - 1; x++)
  264.                 txt[x] = txt[x + 1];
  265.  
  266.             update = 1;
  267.         }
  268.         break;
  269.         
  270.     case 0x0e08:        /* BACKSPACE deletes character before cursor (if any) */
  271.         if (cursor_pos)
  272.         {
  273.             for(x = cursor_pos; x < ed_txt->te_txtlen; x++)
  274.                 txt[x - 1] = txt[x];
  275.                 
  276.             wt->edit_pos--;
  277.             ed_txt->te_tmplen = wt->edit_pos;
  278.  
  279.             update = 1;
  280.         }
  281.         break;
  282.             
  283.     case 0x0f09:        /* TAB moves to next field */
  284.     case 0x5000:        /* DOWN ARROW also moves to next field */
  285.         if (form[ed_obj].ob_flags & LASTOB)    /* Loop round */
  286.             o = 0;
  287.         else
  288.             o = ed_obj;
  289.                 
  290.         for(o++; !(form[o].ob_flags & EDITABLE); o++)        /* search for next editable object */
  291.         {
  292.             if (form[o].ob_flags & LASTOB)    /* Loop round */
  293.                 o = 0;
  294.         }
  295.  
  296.         break;
  297.  
  298.     case 0x5032:        /* SHIFT+DOWN ARROW moves to last field */
  299.         for(last_ob = 0; !(form[last_ob].ob_flags & LASTOB) ; last_ob++); /*find last object*/
  300.         o = last_ob;
  301.         for(; !(form[o].ob_flags & EDITABLE); o--) ;        /* search for last editable object */
  302.         break;
  303.         
  304.     case 0x4800:    /* UP ARROW moves to previous field */
  305.         for(last_ob = 0; !(form[last_ob].ob_flags & LASTOB) ; last_ob++); /*find last object*/
  306.         
  307.         if (ed_obj == 1)    /* Loop round ? */
  308.             o = last_ob + 1;
  309.         else
  310.             o = ed_obj;
  311.                 
  312.         for(o--; !(form[o].ob_flags & EDITABLE); o--)        /* search for previous editable object */
  313.         {
  314.             if (o == 1)    /* Loop round */
  315.                 o = last_ob + 1;
  316.         }
  317.             
  318.         break;
  319.  
  320.     case 0x4838:        /* SHIFT+UP ARROW moves to first field */
  321.         o = 0;
  322.         for(o++; !(form[o].ob_flags & EDITABLE); o++) ;    /* search for first editable object */
  323.         break;
  324.             
  325.     case 0x4d00:    /* RIGHT ARROW moves cursor right */
  326.         if ((txt[cursor_pos]) && (cursor_pos < ed_txt->te_txtlen - 1))
  327.         {
  328.             wt->edit_pos++;
  329.             ed_txt->te_tmplen = wt->edit_pos;
  330.             update = 1;
  331.         }
  332.         break;
  333.  
  334.     case 0x4d36:    /* SHIFT+RIGHT ARROW move cursor to far right of current text */
  335.         for(x = 0; txt[x]; x++) ;
  336.             
  337.         if (x != cursor_pos)
  338.         {
  339.             wt->edit_pos = x;
  340.             ed_txt->te_tmplen = wt->edit_pos;
  341.             update = 1;
  342.         }
  343.         break;
  344.             
  345.     case 0x4b00:    /* LEFT ARROW moves cursor left */
  346.         if (cursor_pos)
  347.         {
  348.             wt->edit_pos--;
  349.             ed_txt->te_tmplen = wt->edit_pos;
  350.             update = 1;
  351.         }
  352.         break;
  353.             
  354.     case 0x4b34:    /* SHIFT+LEFT ARROW move cursor to start of field */
  355.     case 0x4700:    /* CLR/HOME also moves to far left */
  356.         if (cursor_pos)
  357.         {
  358.             wt->edit_pos = ed_txt->te_tmplen = 0;
  359.             update = 1;
  360.         }
  361.         break;
  362.  
  363.     case 0x1c0d:    /* Return - select default (if any) */
  364.         o = 0;
  365.         do{
  366.             if (form[o].ob_flags & DEFAULT)
  367.             {
  368.                 clients[wt->owner].waiting_pb->intout[0] = o;
  369.                 Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long), &retv);    /* Write success to clients reply pipe to unblock the process */
  370.                 if (!(wind->created_by_FMD_START))    /* If FMD_START didn't create this window, destroy it now */
  371.                 {                                    /* - if it did, then we expect the app to call FMD_FINISH to delete the window */
  372.                     clear_clip();
  373.                     clients[wt->owner].zen = NULL;
  374.                     v_hide_c(V_handle);
  375.                     display_windows_below(wind);
  376.                     v_show_c(V_handle, 1);
  377.                     wind->is_open = FALSE;
  378.                     delete_window(wind);
  379.                 }
  380.                 return TRUE;
  381.             }
  382.             o++;
  383.         } while(!(form[o].ob_flags & LASTOB));
  384.         break;
  385.         
  386.     default:        /* Just a plain key - insert character */
  387.         if (cursor_pos == ed_txt->te_txtlen - 1) {
  388.             cursor_pos--;
  389.             wt->edit_pos--;        /* Increased below */
  390.         }
  391.  
  392.         key = keycode & 0xff;
  393.         tmask=character_type[key];
  394.  
  395.         n = strlen(ed_txt->te_pvalid) - 1;
  396.         if (cursor_pos < n)
  397.             n = cursor_pos;
  398.  
  399.         switch(ed_txt->te_pvalid[n]) {
  400.         case '9':
  401.             tmask &= CGd;
  402.             break;
  403.         case 'a':
  404.             tmask &= CGa|CGs;
  405.             break;
  406.         case 'n':
  407.             tmask &= CGa|CGd|CGs;
  408.             break;
  409.         case 'p':
  410.             tmask &= CGa|CGd|CGp|CGxp;
  411.             /*key = toupper((char)key);*/
  412.             break;
  413.         case 'A':
  414.             tmask &= CGa|CGs;
  415.             key = toupper((char)key);
  416.             break;
  417.         case 'N':
  418.             tmask &= CGa|CGd|CGs;
  419.             key = toupper((char)key);
  420.             break;
  421.         case 'F':
  422.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  423.             /*key = toupper((char)key);*/
  424.             break;
  425.         case 'f':
  426.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  427.             /*key = toupper((char)key);*/
  428.             break;
  429.         case 'P':
  430.             tmask &= CGa|CGd|CGp|CGxp|CGw;
  431.             /*key = toupper((char)key);*/
  432.             break;
  433.         case 'X':
  434.             tmask = 1;
  435.             break;
  436.         case 'x':
  437.             tmask = 1;
  438.             key = toupper((char)key);
  439.             break;
  440.         default:
  441.             tmask = 0;
  442.             break;            
  443.         }
  444.             
  445.         if (!tmask) {
  446.             for(n = x = 0; ed_txt->te_ptmplt[n]; n++) {
  447.                    if (ed_txt->te_ptmplt[n] == '_')
  448.                     x++;
  449.                 else if ((ed_txt->te_ptmplt[n] == key)
  450.                     && (x >= cursor_pos))
  451.                     break;
  452.             }
  453.             if (key && (ed_txt->te_ptmplt[n] == key)) {
  454.                 for(n = cursor_pos; n < x; n++)
  455.                     txt[n] = ' ';
  456.                 txt[x] = '\0';
  457.                 wt->edit_pos = x;
  458.                 ed_txt->te_tmplen = wt->edit_pos;
  459.             } else {
  460.                 wt->edit_pos = ed_txt->te_tmplen;
  461.                 return(TRUE);
  462.             }
  463.         } else {
  464.             txt[ed_txt->te_txtlen - 2] = '\0';    /* Needed! */
  465.             for(x = ed_txt->te_txtlen - 1; x > cursor_pos; x--)
  466.                 txt[x] = txt[x - 1];
  467.  
  468.             txt[cursor_pos] = (char)key;
  469.  
  470.             wt->edit_pos++;
  471.             ed_txt->te_tmplen = wt->edit_pos;
  472.         }
  473.             
  474.         update = 1;
  475.         break;
  476.     }
  477.     if (update) {        /* Moved from a number of places above. */
  478.         CLIP(form, ed_obj, x, y, w, h);
  479.         v_hide_c(V_handle);
  480.         draw_object_tree(form, ed_obj, MAX_DEPTH);
  481.         v_show_c(V_handle, 1);
  482.     }
  483.     switch(keycode) {    /* Moved from four places above. */
  484.     case 0x0f09:        /* All the common updating is */
  485.     case 0x5000:        /* done here now. */
  486.     case 0x5032:
  487.     case 0x4800:
  488.     case 0x4838:
  489.         if (o != ed_obj)    /* If edit field has changed, update the display */
  490.         {
  491.             form[o].ob_state |= IS_EDIT;
  492.             form[ed_obj].ob_state &= ~IS_EDIT;
  493.             
  494.             CLIP(form, ed_obj, x, y, w, h);
  495.             v_hide_c(V_handle);
  496.             draw_object_tree(form, ed_obj, MAX_DEPTH);
  497.  
  498.             wt->edit_obj = o;
  499.             wt->edit_pos = ((TEDINFO*)form[o].ob_spec)->te_tmplen = strlen(((TEDINFO*)form[o].ob_spec)->te_ptext);
  500.         
  501.             CLIP(form, o, x, y, w, h);
  502.             draw_object_tree(form, o, MAX_DEPTH);
  503.             v_show_c(V_handle, 1);
  504.         }
  505.         break;
  506.     }
  507.             
  508.     return TRUE;
  509. }
  510.